//故事
var Dao = require('./DAO')
var storyDAO = {
    getALLStory: function (callback) {
        Dao('SELECT content,images,storyTime,userName,headPic FROM storys,users where storys.userId=users.userId', null, function (err, results) {
            if (err) {
                console.log('测试')
                callback(err, null)
            }
            else {
                
                callback(null, results)
            }
        })
    },
    getStoryId: function (storysID,callback) {
        Dao('SELECT content,images,storyTime,userName,headPic FROM storys,users where storys.userId=users.userId and storysID =?',[storysID], function (err, results) {
            if (err) {
                callback(err, null)
            } else{
                callback(null,results)
            }
        })
    },
    getbackStoryId: function (storysID,callback) {
        Dao('SELECT storyreplycontent,storyreplyTime,userName,headPic FROM backstorys,users WHERE users.userId=backstorys.userId and storysID=?',[storysID], function (err, results) {
            if (err) {
                callback(err, null)
            } else{
                callback(null,results)
            }
        })
    },

    insertBackStory:function(backstorys,callback){
        console.log(backstorys)
        Dao('INSERT into backstorys(storyreplycontent,storysID,userId) VALUES(?,?,?)',[backstorys.storyreplycontent,backstorys.storysID,backstorys.userId],function (err, results) {
            if (err) {
                callback(err, null)
            } else{
                callback(null,results)
            }
        })
    }, 
    insertStory:function(storys,callback){
        Dao('INSERT INTO storys(userId ,content) VALUES(?,?)',[storys.userId,storys.content],function (err, results) {
            if (err) {
                callback(err, null)
            } else{
                callback(null,results)
            }
        })
    }, 
    delBackStory:function(storyreplyID,callback){
        Dao('delete from backstorys where storyreplyID=?',[storyreplyID],function (err, results) {
            if (err) {
                callback(err, null)
            } else{
                callback(null,results)
            }
        })
    }, 
    delStory:function(storysID,callback){
        Dao('delete from storys where storysID=?',[storysID],function (err, results) {
            if (err) {
                
                callback(err, null)
            } else{
                callback(null,results)
            }
        })
    }, 
}
module.exports = storyDAO